home *** CD-ROM | disk | FTP | other *** search
- /*
- Version History:
- 2.0 Nov 5 95
- Corrected CenterRect - the original algorithm ended up always
- making innerRect an even height and width. I had used it for
- over a year without noticing! (Probably because most of the
- time all my rects were even-sized...)
- */
-
- #include <Palettes.h>
- #include "QDUtils.h"
-
- void CopyBitsToWindow(GWorldPtr sourceGWorld, WindowPtr destWindow, Rect *sourceR, Rect *destR, RgnHandle theClip) {
- (void)LockPixels(GetGWorldPixMap(sourceGWorld));
- CopyBits(GetGWorldBits(sourceGWorld), GetWindowBits(destWindow), sourceR, destR, srcCopy, theClip);
- UnlockPixels(GetGWorldPixMap(sourceGWorld));
- } // END CopyBitsToWindow
-
- void CopyBitsToGWorld(GWorldPtr sourceGWorld, GWorldPtr destGWorld, Rect *sourceR, Rect *destR, RgnHandle theClip) {
- (void)LockPixels(GetGWorldPixMap(sourceGWorld));
- (void)LockPixels(GetGWorldPixMap(destGWorld));
- CopyBits(GetGWorldBits(sourceGWorld), GetGWorldBits(destGWorld), sourceR, destR, srcCopy, theClip);
- UnlockPixels(GetGWorldPixMap(sourceGWorld));
- UnlockPixels(GetGWorldPixMap(destGWorld));
- } // END CopyBitsToGWorld
-
- // ---------------------------------------------------------------------------
-
- void CenterRect(Rect *innerRect, Rect *outerRect) {
- short outerRectWidth = outerRect->right - outerRect->left;
- short outerRectHeight = outerRect->bottom - outerRect->top;
- short innerRectWidth = innerRect->right - innerRect->left;
- short innerRectHeight = innerRect->bottom - innerRect->top;
- short hDiff = (outerRectWidth - innerRectWidth) / 2;
- short vDiff = (outerRectHeight - innerRectHeight) / 2;
- innerRect->left = outerRect->left + hDiff;
- innerRect->right = innerRect->left + innerRectWidth;
- innerRect->top = outerRect->top + vDiff;
- innerRect->bottom = innerRect->top + innerRectHeight;
- } // END CenterRect
-
- void MoveRectTo(Rect *theRect, short h, short v) {
- register short width = theRect->right - theRect->left;
- register short height = theRect->bottom - theRect->top;
- theRect->left = h;
- theRect->top = v;
- theRect->right = theRect->left + width;
- theRect->bottom = theRect->top + height;
- } // END MoveRectTo
-
- void FlushRectTopLeft(Rect *theRect) {
- MoveRectTo(theRect, 0, 0);
- } // END FlushRectTopLeft
-
- void MoveRgnTo(short hLoc, short vLoc, RgnHandle theRgn) {
- register short hDiff;
- register short vDiff;
- hDiff = hLoc - (**theRgn).rgnBBox.left;
- vDiff = vLoc - (**theRgn).rgnBBox.top;
- OffsetRgn(theRgn, hDiff, vDiff);
- } // END MoveRgnTo
-
- void MoveRgnToRect(Rect *theRect, RgnHandle theRgn) {
- register short hDiff;
- register short vDiff;
- vDiff = theRect->top - (**theRgn).rgnBBox.top;
- hDiff = theRect->left - (**theRgn).rgnBBox.left;
- OffsetRgn(theRgn, hDiff, vDiff);
- } // END MoveRgnToRect
-
- // ---------------------------------------------------------------------------
-
- /*
- CenterText does as its name implies: centers the text for you. Some points
- worth of note:
- a) You should set the port, font, fontsize, and font face first before
- calling CenterText().
-
- b) CenterText() centers the text by calling _MoveTo.
-
- c) If horizCenter & vertCenter are both false, the routine positions
- the pen at the bottom left corner of destRect.
- */
-
- void CenterText(Str255 theText, Rect *destRect, Boolean horizCenter, Boolean vertCenter) {
- short strWidth; // Length of string, in pixels.
- short strHeight; // Height of string, in pixels.
- short hDest, vDest;
- FontInfo fInfo;
-
- GetFontInfo(&fInfo);
-
- strHeight = fInfo.ascent + fInfo.descent + fInfo.leading;
- strWidth = StringWidth(theText);
-
- hDest = ((destRect->right - destRect->left) - strWidth) >> 1;
- vDest = ((destRect->bottom - destRect->top) - strHeight) >> 1;
-
- if (horizCenter)
- hDest = destRect->left + hDest;
- else
- hDest = destRect->left; // Don't center, thus make no change in horiz position
-
- if (vertCenter)
- vDest = destRect->bottom - vDest;
- else
- vDest = destRect->bottom;
-
- MoveTo(hDest, vDest);
- } // END CenterText
-
- // ---------------------------------------------------------------------------
-
- void SetMonitorDepth(GDHandle monitor, short depth, Boolean color) {
- short flags;
-
- if (monitor != NULL) {
- flags = 1 << gdDevType;
- (void)SetDepth(monitor, depth, flags, color ? 1 : 0);
- }
- } // END SetMonitorDepth
-
- // ---------------------------------------------------------------------------
-
- Boolean HasMonitorDepth(GDHandle monitor, short depth, Boolean color) {
- short flags;
-
- if (monitor != NULL) {
- color = true;
- flags = 1 << gdDevType;
- return(HasDepth(monitor, depth, flags, color ? 1 : 0));
- }
- else
- return(false);
- } // END HasMonitorDepth